﻿Imports System.Data.SqlClient
Public Class frmGruposDeGastos
    Dim res As DialogResult


    Private Sub frmGruposDeGastos_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            listaGruposDeGastos()
            actualizaValorGrupo()
        Catch ex As Exception
            mensajeError(ex)

        End Try
    End Sub

    Private Sub btnIngresar_Click(sender As Object, e As EventArgs) Handles btnIngresar.Click
        Try


            If txtNombre.Text = "" Then
                MessageBox.Show(msjCampoBlanco, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtNombre.Focus()
            Else
                res = MessageBox.Show(msjIngreso, msjTituloModal, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

                If res = Windows.Forms.DialogResult.Yes Then

                    ingresaGruposDeGastos(txtNombre.Text)
                    ActualizaValoresDeGrupos()
                    datosCBGrupoGastos()
                    txtNombre.Clear()
                    txtNombre.Focus()

                Else
                    txtNombre.Focus()

                End If
            End If

        Catch ex As Exception
            mensajeError(ex)
        End Try
    End Sub

    Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles btnEliminar.Click

        res = MessageBox.Show(msjEliminar, msjTituloModal, MessageBoxButtons.YesNo, MessageBoxIcon.Question)


        Try
            With DGV_Grupos

                If .CurrentRow Is Nothing And res = Windows.Forms.DialogResult.Yes Then

                    MessageBox.Show(msjDatoAEliminar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Information)

                ElseIf .CurrentRow IsNot Nothing And res = Windows.Forms.DialogResult.Yes Then

                    Dim pID As Integer 'parametro ID
                    Dim pValor As Integer
                    pID = .Item(0, .CurrentRow.Index).Value
                    pValor = .Item(2, .CurrentRow.Index).Value

                    eliminaGruposDeGastos(pID, pValor)

                End If

            End With


        Catch ex As Exception
            mensajeError(ex)
        End Try




    End Sub

    Private Sub btnEditar_Click(sender As Object, e As EventArgs) Handles btnEditar.Click
        Dim pID As Integer
        Dim pNom As String = ""
        Dim pValor As Integer




        Try

            With DGV_Grupos

                res = MessageBox.Show(msjActualizar, msjTituloModal, MessageBoxButtons.YesNo, MessageBoxIcon.Question)


                If .CurrentRow Is Nothing And res = Windows.Forms.DialogResult.Yes Then

                    MessageBox.Show(msjDatoAActualizar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Information)

                ElseIf res = DialogResult.Yes Then

                    pID = .Item(0, .CurrentCell.RowIndex).Value
                    pNom = .Item(1, .CurrentCell.RowIndex).Value
                    pValor = .Item(2, .CurrentCell.RowIndex).Value


                    actualizaGrupoGastos(pID, pNom, pValor)
                End If

            End With



        Catch ex As Exception
            mensajeError(ex)

        End Try
    End Sub


   

End Class